package cz.myslivec.slovicka.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name="TESTED_VOC")
public class TestedVocable implements Serializable {
	private static final long serialVersionUID = -4757184016101951287L;
	
	@Id
	@Column(name = "ID_TV")
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;

	@ManyToOne
	@JoinColumn(name="ID_VOC")
	private Vocable vocable;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="TEST_DATE")
	private Date testDate;
	
	@Column(name = "SUCCESS_LEVEL", nullable=false)
	private Integer successLevel;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="NEXT_TEST_DATE")
	private Date nextTestDate;
	
	@Column(name="E_FACTOR", nullable=false)
	private BigDecimal eFactor = new BigDecimal(2.5);
	
	@Column(name="TEST_COUNT", nullable=false)
	private Integer testCount = new Integer(1);

	@Column(name="TEST_INTERVAL", nullable=false)
	private Integer testInterval = new Integer(1);
	
	/**
	 * attribute just for converting xml DTO to entity (during importing DB)
	 */
	@Transient
	private Long vocableId;
	
	public TestedVocable() {
		super();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Vocable getVocable() {
		return vocable;
	}

	public void setVocable(Vocable vocable) {
		this.vocable = vocable;
	}

	public Integer getSuccessLevel() {
		return successLevel;
	}

	public void setSuccessLevel(Integer successLevel) {
		this.successLevel = successLevel;
	}

	public Date getTestDate() {
		return testDate;
	}

	public void setTestDate(Date testDate) {
		this.testDate = testDate;
	}


	public Long getVocableId() {
		return vocableId;
	}

	public void setVocableId(Long vocableId) {
		this.vocableId = vocableId;
	}

	public Date getNextTestDate() {
		return nextTestDate;
	}

	public void setNextTestDate(Date nextTestDate) {
		this.nextTestDate = nextTestDate;
	}

	public BigDecimal geteFactor() {
		return eFactor;
	}

	public void seteFactor(BigDecimal eFactor) {
		this.eFactor = eFactor;
	}

	public Integer getTestCount() {
		return testCount;
	}

	public void setTestCount(Integer testCount) {
		this.testCount = testCount;
	}

	public Integer getTestInterval() {
		return testInterval;
	}

	public void setTestInterval(Integer testInterval) {
		this.testInterval = testInterval;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TestedVocable other = (TestedVocable) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "TestedVocable [id=" + id + ", vocable=" + vocable
				+ ", testDate=" + testDate + ", successLevel=" + successLevel
				+ ", nextTestDate=" + nextTestDate + ", eFactor=" + eFactor
				+ ", testCount=" + testCount + ", testInterval=" + testInterval
				+ ", vocableId=" + vocableId + "]";
	}
	
}
